﻿<%@ Page Language="C#" MasterPageFile="~/Web.master" AutoEventWireup="true" CodeBehind="TabFld.aspx.cs"
  Inherits="XFSale.Aux.TabFldPage" %>

<asp:Content ID="partMain" ContentPlaceHolderID="partMain" runat="server">
  <asp:SqlDataSource ID="dsTab" runat="server" ConnectionString="<%$ ConnectionStrings:txfund %>"
    ProviderName="<%$ ConnectionStrings:txfund.ProviderName %>" OldValuesParameterFormatString="old_{0}"
    SelectCommand="select * from XmTabFld where upper(tabName) = upper(:tabName) order by upper(tabName), fldOrder"
    UpdateCommand="update XmTabFld set fldDesc=:fldDesc, fldType=:fldType, fldScale=:fldScale, fldPrecise=:fldPrecise, fldNull=:fldNull, fldPK=:fldPK, fldDefault=:fldDefault, fldOrder=:fldOrder, summary=:summary where tabName=:old_tabName and fldName=:old_fldName"
    InsertCommand="insert into XmTabFld(tabName, fldName, fldDesc, fldType, fldScale, fldPrecise, fldNull, fldPK, fldDefault, summary) values(:tabName, :fldName, :fldDesc, :fldType, :fldScale, :fldPrecise, :fldNull, :fldPK, :fldDefault, :summary)"
    DeleteCommand="delete from XmTabFld where tabName=:old_tabName and fldName=:old_fldName">
  </asp:SqlDataSource>
  <asp:SqlDataSource ID="dsItem" runat="server" ConnectionString="<%$ ConnectionStrings:txfund %>"
    ProviderName="<%$ ConnectionStrings:txfund.ProviderName %>" SelectCommand="select tabName, tabName as tabText from XmTab order by upper(tabName)">
  </asp:SqlDataSource>
  <table runat="server" id="pnlSearch" width="100%" class="search">
    <tr>
      <td>
        数据表名称
        <asp:DropDownList runat="server" ID="ddlTabName" DataSourceID="dsItem" DataTextField="tabText"
          AutoPostBack="true" DataValueField="tabName" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTabName_SelectedIndexChanged">
          <asp:ListItem Value="">-不限定-</asp:ListItem>
        </asp:DropDownList>
        <%--
        <asp:RequiredFieldValidator runat="server" ValidationGroup="Search" ControlToValidate="txtItemName" ErrorMessage="请输入检索条件"
          EnableClientScript="true" />
        --%>
      </td>
      <td align="right" valign="middle">
        <asp:ImageButton runat="server" ID="btnInsert" ToolTip="新增" ImageUrl="~/image/gb.gif"
          ValidationGroup="Action" ImageAlign="AbsMiddle" OnClick="btnInsert_Click" />
      </td>
    </tr>
  </table>
  <asp:GridView ID="gvTab" runat="server" DataSourceID="dsTab" PageSize="15" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" Width="100%" BackColor="White"
    BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1" CellPadding="3" DataKeyNames="tabName,fldName"
    ForeColor="Black" GridLines="None" OnRowCommand="gvTab_RowCommand" OnRowDataBound="gvTab_RowDataBound">
    <FooterStyle BackColor="#CCCC99" />
    <RowStyle BackColor="#F7F7DE" />
    <Columns>
      <%--
      <asp:BoundField DataField="TabName" ReadOnly="True" HeaderText="表名" SortExpression="ItemName"
        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" />
      --%>
      <asp:BoundField DataField="FldName" ReadOnly="True" HeaderText="字段名" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldDesc" HeaderText="描述" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldType" HeaderText="类型" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldScale" HeaderText="长度" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldPrecise" HeaderText="精度" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldNull" HeaderText="为空?" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldPK" HeaderText="主键?" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldOrder" HeaderText="顺序" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:BoundField DataField="FldDefault" HeaderText="缺省值" ItemStyle-HorizontalAlign="Left"
        HeaderStyle-HorizontalAlign="Left" />
      <asp:TemplateField HeaderText="操作">
        <ItemStyle HorizontalAlign="Right" />
        <HeaderStyle HorizontalAlign="Right" />
        <ItemTemplate>
          <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="~/image/btn_edit.gif" CommandName="Edit" />
          <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/image/btn_delete2.gif"
            CommandName="Delete" OnClientClick="return confirm('确定删除此字段？');" />
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
    <PagerSettings Mode="NumericFirstLast" PageButtonCount="10" />
    <PagerStyle HorizontalAlign="Right" CssClass="pager" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
  </asp:GridView>
  <asp:FormView ID="fvTab" runat="server" DataSourceID="dsTab" DefaultMode="Edit" Width="100%"
    Visible="False" DataKeyNames="tabName,fldName" OnItemInserted="fvTab_ItemInserted"
    OnItemUpdated="fvTab_ItemUpdated" OnItemCommand="fvTab_ItemCommand" OnPreRender="fvTab_PreRender"
    OnItemInserting="fvTab_ItemInserting">
    <EditItemTemplate>
      <table>
        <tr>
          <td>
            数据表名称：
          </td>
          <td>
            <asp:TextBox ID="txtTabName" runat="server" Text='<%# Bind("tabName") %>' Columns="30" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="txtTabName" ErrorMessage="数据表名称必须填写"
              EnableClientScript="true" Display="Dynamic" />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="txtTabName" ValidationExpression="^\w{1,30}$"
              ErrorMessage="数据表名称不合法" EnableClientScript="true" Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            字段名称：
          </td>
          <td>
            <asp:TextBox ID="txtFldName" runat="server" Text='<%# Bind("fldName") %>' Columns="30" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="txtFldName" ErrorMessage="字段名称必须填写"
              EnableClientScript="true" Display="Dynamic" />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="txtFldName" ValidationExpression="^\w{1,30}$"
              ErrorMessage="字段名称不合法" EnableClientScript="true" Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            字段描述：
          </td>
          <td>
            <asp:TextBox ID="txtFldDesc" runat="server" Text='<%# Bind("fldDesc") %>' Columns="45" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="txtFldDesc" ErrorMessage="字段描述必须填写"
              EnableClientScript="true" Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            字段类型：
          </td>
          <td>
            <asp:DropDownList ID="ddlFldType" runat="server">
              <asp:ListItem Value="VARCHAR" Text="VARCHAR" />
              <asp:ListItem Value="CHAR" Text="CHAR" />
              <asp:ListItem Value="NUMBER" Text="NUMBER" />
            </asp:DropDownList>
            <span class="required">*</span>
          </td>
        </tr>
        <tr>
          <td>
            字段长度：
          </td>
          <td>
            <asp:TextBox ID="txtFldScale" runat="server" Text='<%# Bind("fldScale") %>' Columns="5" />
            <span class="required">*</span>
            <asp:RequiredFieldValidator runat="server" ControlToValidate="txtFldScale" ErrorMessage="字段长度必须填写"
              EnableClientScript="true" Display="Dynamic" />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="txtFldScale" ValidationExpression="^\d{1,3}$"
              ErrorMessage="字段长度不合法" EnableClientScript="true" Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            字段精度：
          </td>
          <td>
            <asp:TextBox ID="txtFldPrecise" runat="server" Text='<%# Bind("fldPrecise") %>' Columns="5" />
            <span class="required">*</span>
            <asp:RequiredFieldValidator runat="server" ControlToValidate="txtFldPrecise" ErrorMessage="字段精度必须填写"
              EnableClientScript="true" Display="Dynamic" />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="txtFldPrecise"
              ValidationExpression="^\d{1,3}$" ErrorMessage="字段精度不合法" EnableClientScript="true"
              Display="Dynamic" />
            <asp:CompareValidator runat="server" ControlToValidate="txtFldPrecise" ControlToCompare="txtFldScale"
              Operator="LessThanEqual" ErrorMessage="字段精度必须小于等于长度" EnableClientScript="true"
              Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            字段顺序：
          </td>
          <td>
            <asp:TextBox ID="txtFldOrder" runat="server" Text='<%# Bind("fldOrder") %>' Columns="5" />
            <asp:RangeValidator runat="server" ControlToValidate="txtFldOrder" Type="Integer"
              MinimumValue="0" MaximumValue="999" ErrorMessage="字段顺序不合法" EnableClientScript="true"
              Display="Dynamic" />
          </td>
        </tr>
        <tr>
          <td>
            允许为空？：
          </td>
          <td>
            <asp:RadioButtonList ID="rblFldNull" runat="server" RepeatDirection="Horizontal"
              RepeatLayout="Flow">
              <asp:ListItem Value="N">否</asp:ListItem>
              <asp:ListItem Value="Y">是</asp:ListItem>
            </asp:RadioButtonList>
          </td>
        </tr>
        <tr>
          <td>
            是否主键？：
          </td>
          <td>
            <asp:RadioButtonList ID="rblFldPK" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
              <asp:ListItem Value="N">否</asp:ListItem>
              <asp:ListItem Value="Y">是</asp:ListItem>
            </asp:RadioButtonList>
          </td>
        </tr>
        <tr>
          <td>
            备注：
          </td>
          <td>
            <asp:TextBox ID="txtSummary" runat="server" TextMode="MultiLine" Text='<%# Bind("summary") %>'
              Columns="45" Rows="3" />
          </td>
        </tr>
      </table>
      <asp:Button ID="btnInsert" runat="server" CausesValidation="True" CommandName="Insert"
        Text="新增" CssClass="button" />
      <asp:Button ID="btnUpdate" runat="server" CausesValidation="True" CommandName="Update"
        Text="更新" CssClass="button" />
      <asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
        Text="取消" CssClass="button" />
    </EditItemTemplate>
  </asp:FormView>
</asp:Content>
